package com.geekaca.news.service.impl;

import com.geekaca.news.domain.Link;
import com.geekaca.news.mapper.LinkMapper;
import com.geekaca.news.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LinkServiceImpl implements LinkService {
    @Autowired
    private LinkMapper linkMapper;

    @Override
    public int getTotalLinks() {
        return linkMapper.getTotalLinks();
    }

    @Override
    public List<Link> getAllLinks(Integer page, Integer limit) {
        Integer start = null;
        Integer pageSize = limit;
        if (page != null) {
            start = (page - 1) * limit;
        }
        return linkMapper.getAllLinks(start, pageSize);
    }

    @Override
    public int insertLink(Link link) {
        int inserted = linkMapper.insert(link);
        return inserted;
    }

    @Override
    public Link getLinkById(Long id) {
        return linkMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateLink(Link link) {
        return linkMapper.updateLink(link);
    }

    @Override
    public int delLink(Long id) {
        return linkMapper.deleteByPrimaryKey(id);
    }
}
